/*****************************************************************************/
/*!	\file		PIS10Callbacks.h
 *	\brief		C header file for the YX-PIS Example
 *	\par		Dalian Yunxing Tech Co., Ltd.
 *
 *				Dalian, China
 *				Phone   : +86 (411) 8825 4852
 *				Email   : yx@yunxing.tech
 */
/*****************************************************************************/

#ifndef CALLBACK_FUNCTIONS_INCLUDED
#define CALLBACK_FUNCTIONS_INCLUDED 1
 
#include <stdio.h>

#include "IEC61850Types.h"

/*!
 *	\brief	the callback function that triggered by SelectActiveSG action
 *
 *	\param[in]	userData	the customized user data
 *	\param[in]	dataMap		the data map of the activated setting group data attribute,
 *							the type is depending on the data-mapping-mode of the IEC61850 object.
 *							maybe type of (IEC61850_DataAttributeID*) or (char*).
 *	\param[in]	newValue	the value of activated setting group data attribute
 *
 *	\return		IEC61850_CallbackReturnServiceErrorCode
 */
IEC61850_CallbackReturnServiceErrorCode WriteCallbackHandler(void* userData, const void* dataMap, const IEC61850_DataAttributeData* newValue);

/*!
 *	\brief	the callback function that indicates a 'Select' control action is being executed
 *
 *	\param[in]	userData			the customized user data
 *	\param[in]	dataMap				the data map info of the data attribute which is being controlled,
 *									the type is depending on the data-mapping-mode of the IEC61850 object.
 *									maybe type of (IEC61850_DataAttributeID*) or (char*).
 *	\param[in]	selectValue			the ctlVal of the SelectWithValues request, or NULL for the Select request.
 *	\param[in]	selectParameters	the other control parameters except the ctlVal
 *
 *	\return		AddCause as the control result,
 *				return IEC61850_COMMAND_ERROR_ADD_CAUSE_NONE as OK, or return other appropriate AddCause value to reject.
 */
eCommandAddCause SelectCallbackHandler(void* userData, const void* dataMap, const IEC61850_DataAttributeData* selectValue, const IEC61850_CommandParameter* selectParameters);

/*!
 *	\brief	the callback function that indicates the selection status of the control object has expired due to timeout
 *
 *	\param[in]	userData	the customized user data
 *	\param[in]	dataMap		the data map info of the data attribute which is being controlled,
 *							the type is depending on the data-mapping-mode of the IEC61850 object.
 *							maybe type of (IEC61850_DataAttributeID*) or (char*).
 *	\param[in]	selectValue	the ctlVal of the SelectWithValues request, or NULL for the Select request.
 *
 *	\return		should always return IEC61850_COMMAND_ERROR_ADD_CAUSE_NONE
 */
eCommandAddCause SelectTimeoutHandler(void* userData, const void* dataMap, const IEC61850_DataAttributeData* selectValue);

/*!
 *	\brief	the callback function that indicates an 'OperativeTest' control action is being executed
 *
 *	\param[in]	userData				the customized user data
 *	\param[in]	dataMap					the data map info of the data attribute which is being controlled,
 *										the type is depending on the data-mapping-mode of the IEC61850 object.
 *										maybe type of (IEC61850_DataAttributeID*) or (char*).
 *	\param[in]	operativeTestParameters	the other control parameters except the ctlVal
 *
 *	\return		AddCause as the OperativeTest result,
 *				return IEC61850_COMMAND_ERROR_ADD_CAUSE_NONE as OK, or return other appropriate AddCause value to reject.
 */
eCommandAddCause OperativeTestCallbackHandler(void* userData, const void* dataMap, const IEC61850_CommandParameter* operativeTestParameters);

/*!
 *	\brief	the callback function that indicates an 'Operate' control action is being executed
 *
 *	\param[in]	userData			the customized user data
 *	\param[in]	dataMap				the data map info of the data attribute which is being controlled,
 *									the type is depending on the data-mapping-mode of the IEC61850 object.
 *									maybe type of (IEC61850_DataAttributeID*) or (char*).
 *	\param[in]	operateValue		Pointer to the selected value that generated the callback
 *	\param[in]	operateParameters	the other control parameters except the ctlVal
 *
 *	\return		AddCause as the control result,
 *				return IEC61850_COMMAND_ERROR_ADD_CAUSE_NONE as OK, or return other appropriate AddCause value to reject.
 */
eCommandAddCause OperateCallbackHandler(void* userData, const void* dataMap, const IEC61850_DataAttributeData* operateValue, const IEC61850_CommandParameter* operateParameters);

/*!
 *	\brief	the callback function that indicates a 'Cancel' control action is being executed
 *
 *	\param[in]	userData			the customized user data
 *	\param[in]	dataMap				the data map info of the data attribute which is being controlled,
 *									the type is depending on the data-mapping-mode of the IEC61850 object.
 *									maybe type of (IEC61850_DataAttributeID*) or (char*).
 *	\param[in]	cancelParameters	the other control parameters except the ctlVal
 *
 *	\return		AddCause as the control result,
 *				return IEC61850_COMMAND_ERROR_ADD_CAUSE_NONE as OK, or return other appropriate AddCause value to reject.
 */
eCommandAddCause CancelCallbackHandler(void* userData, const void* dataMap, const IEC61850_CommandParameter* cancelParameters);

/*!
 *	\brief	the callback function that indicates the CommandTermination of enhanced-security control process
 *
 *	\param[in]	userData		the customized user data
 *	\param[in]	dataMap			the data map info of the data attribute which is being controlled,
 *								the type is depending on the data-mapping-mode of the IEC61850 object.
 *								maybe type of (IEC61850_DataAttributeID*) or (char*).
 *	\param[in]	controlResult	the control feedback info in the CommandTermination request
 *
 *	\return  	should always return IEC61850_COMMAND_ERROR_ADD_CAUSE_NONE
 */
eCommandAddCause CommandTerminationCallback(void* userData, const void* dataMap, const ControlResult* controlResult);

/*!
 *	\brief	the callback function that indicates the data update info is received.
 *			may triggered by Report/GOOSE/SV message.
 *
 *	\param[in]	userData	the customized user data
 *	\param[in]	dataMap		the data map info of the updated data attribute,
 *							the type is depending on the data-mapping-mode of the IEC61850 object.
 *							maybe type of (IEC61850_DataAttributeID*) or (char*).
 *	\param[in]	newValue	the new value of the updated data attribute
 *
 *	\return		None
 */
void UpdateCallbackHandler(void* userData, const void* dataMap, const IEC61850_DataAttributeData* newValue);

/*!
 *	\brief	the callback function that indicates the data update info is received,
 *			and the updated data value will be represented in units of FCDA.
 *
 *	\param[in]	userData	the customized user data
 *	\param[in]	dataMap		the data map info of the updated data attribute,
 *							the type is depending on the data-mapping-mode of the IEC61850 object.
 *							maybe type of (IEC61850_DataAttributeID*) or (char*).
 *	\param[in]	newValue	the updated data attribute(s) value(s) in units of FCDA
 *	\param[in]	dataNum		the number of values contains in newValue
 *
 *	\return		None
 */
void FCDAUpdateCallbackHandler(void* userData, const void* dataMap, const IEC61850_DataAttributeData* newValue, unsigned int dataNum);

/*!
 *	\brief	the callback function that indicates the occurrence of GOOSE TAL(time-allowed-to-live) timeout.
 *
 *	\param[in]	userData	the customized user data
 *	\param[in]	daid		the data attribute id of subscribed GOOSE data attribute
 *
 *	\return  None
 */
void QuestionableCallbackHandler(void* userData, const IEC61850_DataAttributeID* daid);

/*!
 *	\brief	the callback function to pre-process the fileName/pathName parameter in file service requests
 *
 *	\param[in]	serviceCode	the ServiceCode value corresponding to the requested file service,
 *							the value will be one of the following:
 *								128: SC_GetFile
 *								129: SC_SetFile
 *								130: SC_DeleteFile
 *								131: SC_GetFileAttributeValues
 *								132: SC_GetFileDirectory
 *	\param[in]	path		the fileName/pathName to be resolved in the file service requests
 *	\param[out]	out			the real fileName/pathName to output
 *	\param[in]	length		the length of fileName/pathName
 *
 *	\return  None
 */
Boolean FilePathResolveCallback(int serviceCode, const char* path, char* out, int length);

/*!
 *	\brief	the callback function to deal with file operations.
 *
 *	\param[in]	userData		the customized user data
 *	\param[in]	fileCallType	the requested file service type
 *	\param[in]	fileAttributes	the file(s) information
 *
 *	\return		IEC61850_FileResponseCode
 */
IEC61850_FileResponseCode FileCallbackHandler(void* userData, IEC61850_FileCallType fileCallType, tFileAttr* fileAttributes);

/*!
 *	\brief	the callback function to deal with setting group operations.
 *
 *	\param[in]		userData	the customized user data
 *	\param[in]		sgOper		represents the operation type of requested setting group service
 *									SG_SELECT_ACTIVE: SelectActiveSG
 *									SG_SELECT_EDIT: SelectEditSG
 *									SG_GET_VALUE: GetEditSGValue
 *									SG_SET_VALUE: SetEditSGValue
 *									SG_CONFIRM_EDIT: ConfirmEditSGValues
 *									SG_GET_SGCB: GetSGCBValues
 *	\param[in,out]	sgParam		setting group parameters
 *									sgOper=SG_SELECT_ACTIVE: type is (SGCallback_Select*), contains the SGCB reference and ActiveSG number
 *									sgOper=SG_SELECT_EDIT: type is (SGCallback_Select*), contains the SGCB reference and EditSG number
 *									sgOper=SG_GET_VALUE: type is (SGCallback_Data*), contains the SG/SE data info
 *									sgOper=SG_SET_VALUE: type is (SGCallback_Data*), contains the SG/SE data info
 *									sgOper=SG_CONFIRM_EDIT: type is (char*), represents the SGCB reference
 *									sgOper=SG_GET_SGCB: type is (char*), represents the SGCB reference
 *
 *	\return		ServiceError, type of eServiceError,
 *				return SERVICE_ERROR_NO_ERROR represents OK,
 *				return SERVICE_ERROR_FAILED_DUE_TO_SERVER_CONSTRAIANT to reject the corresponding operation
 */
eServiceError SettingGroupCallback(void* userData, IEC61850_SettingGroup_Operation sgOper, void* sgParam);

/*!
 *	\brief	the callback function that indicates connection status changes.
 *
 *	\param[in]	userData				the customized user data
 *	\param[in]	connectedServersArray	represents the connection status info of every IED
 *
 *	\return		none
 */
void ConnectionStatusCallbackHandler(void* userData, IEC61850_ServerStatusArray connectedServersArray);

/*!
 *	\brief	a method example of RpcCall
 *
 *	\param[in]		reqData		the data of RpcCall request
 *	\param[in,out]	respData	the data of RpcCall response
 *
 *	\return		none
 */
void RpcCallTest(RpcData* reqData, RpcData* respData);

#endif
